package com.kc.gb.device.plugins.ptl.service.support.ableat.drivers;


import ATOPSTD.AbleAPI;
import ATOPSTD.AbleLightAPI;
import com.kc.gb.device.common.properties.DeviceProperties;
import com.kc.gb.device.plugins.ptl.service.support.ableat.ABLEATPtlService;
import com.kc.gb.feign.ptl.support.enums.*;

import javax.annotation.Resource;

public abstract class AbstractAbleLightService implements ABLEATPtlService {

    @Resource
    DeviceProperties deviceProperties;

    @Override
    public void light(int lightNo, PtlLightOnOff lightStatus, PtlLightColor color, short interval){
        int machineId = getMachineId();
        AbleAPI.AB_LED_Status(machineId, (short)getRealLightPosition(lightNo), color.getCode(), lightStatus.getCode());
        AbleLightAPI.light(machineId, (short)getRealLightPosition(lightNo), lightStatus.getCode(),interval);
    }

    @Override
    public void lednum(int lightNo, int num, PtlLedOnOff ledStatus){
        int machineId = getMachineId();
        AbleLightAPI.lednum(machineId,(short)getRealLightPosition(lightNo),num,ledStatus.getCode());
    }

    @Override
    public void button(int lightNo, PtlButtonStatus buttonStatus){
        int machineId = getMachineId();
        AbleLightAPI.button(machineId,(short)getRealLightPosition(lightNo),buttonStatus.getCode());
    }

    @Override
    public void beep(int lightNo, PtlBeepStatus beepStatus){
        int machineId = getMachineId();
        AbleLightAPI.beep(machineId,(short)getRealLightPosition(lightNo),beepStatus.getCode());
    }

    private int getMachineId(){
        return deviceProperties.getDevicePtlControlID();
    }

    private int getRealLightPosition(int lightPosition) {
        return lightPosition * getRatio();
    }

    public abstract int getRatio();
}
